package com.briup.jd2407cms.web.controller;

import com.briup.jd2407cms.domain.Slideshow;
import com.briup.jd2407cms.result.Result;
import com.briup.jd2407cms.service.SlideshowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "轮播图管理")
@RestController
@RequestMapping("/slideshow")
public class SlideshowController {

    @Autowired
    SlideshowService slideshowService;

    @GetMapping("/queryById/{id}")
    public Result<Slideshow> findById(@PathVariable Integer id){
        Slideshow slideshow = slideshowService.getById(id);
        return Result.success(slideshow);
    }

    @GetMapping("/queryAllEnable")
    public Result<?> findAllEnable(){
        List<Slideshow> slideshows = slideshowService.queryAllEnable();
        return Result.success(slideshows);
    }

    @ApiOperation("分页条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "条数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "desc",value = "轮播图描述",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "status",value = "状态，是否启用",paramType = "query",dataType = "java.lang.String"),
    })
    @GetMapping("/query")
    public Result<?> findAllByPageByCondition(@RequestParam Integer pageNum,
                                              @RequestParam Integer pageSize,
                                              String desc, String status){
        return Result.success(slideshowService.findAllByPageByCondition(pageNum, pageSize, desc, status));
    }
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdate(@RequestBody Slideshow slideshow){
        return Result.success();
    }
    @DeleteMapping("/deleteByBatch/{ids}")
    public Result<?> remove(@PathVariable List<Integer> ids){
        // 直接使用mp中提供的删除方法（可）
        // slideshowService.removeByIds(ids);

        // 自己写删除逻辑
        return Result.success();
    }

}
